#!/bin/bash

version="1.66"

if [[ $1 == "--help" || $1 == "-h" ]];then
	echo "$credits"
	echo ""
	echo "  -t, --temp        Keep temp files"
	echo ""
	exit 0
fi

cd builds
rm std-install.sh
if [[ -d temp ]]; then
	rm -R temp
fi
mkdir temp
cd ..
cat ./add > "./builds/temp/add.sh"
chmod +x ./builds/temp/add.sh
echo "version=\"$version\"" >> "./builds/temp/add.sh"

cat ./distributions >> "./builds/temp/add.sh"

echo "distribution_name_array=(\$distribution_name)" >> "./builds/temp/add.sh"
echo "distribution_text_array=(\$distribution_text)" >> "./builds/temp/add.sh"

echo "install_array=\"b\"" >> "./builds/temp/add.sh"
echo "fil=\"remove\"" >> "./builds/temp/add.sh"
cat ./remove >> "./builds/temp/add.sh"

echo "install_array=\"c\"" >> "./builds/temp/add.sh"
echo "fil=\"addon\"" >> "./builds/temp/add.sh"
cat ./addon >> "./builds/temp/add.sh"

echo "install_array=\"a\"" >> "./builds/temp/add.sh"
echo "fil=\"installer\"" >> "./builds/temp/add.sh"
cat ./installer >> "./builds/temp/add.sh"

echo "samle" >> "./builds/temp/add.sh"

cp "check_version" ./builds/temp
cp "zenity" ./builds/temp
cp "parameters1" ./builds/temp
cp "parameters2" ./builds/temp
cp "parameters3" ./builds/temp
cp "parameters4" ./builds/temp
cp "parameters5" ./builds/temp
cp "parameters6" ./builds/temp
cp "parameters7" ./builds/temp
cp "addonfunktions" ./builds/temp
cp "first-install" ./builds/temp
cp "end" ./builds/temp

cd builds
cd temp
./add.sh
cd ..
mv "./temp/std-install.sh" "./"
if [[ $1 == "--temp" || $1 == "-t" ]];then
	echo "Keeping temp files!"
else
#	echo "Delete temp"
	rm -R temp
fi
cd builds
zip std-install.sh.zip *
cd ..
zip std-install-source.zip *
cd web
rm *.zip
cd ..
mv builds/std-install.sh.zip web/
mv std-install-source.zip web/
echo $version > web/version
